﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Main.Master" AutoEventWireup="true"
    CodeBehind="OnWayTrackManagement.aspx.cs" Inherits="NetDon.OA.Portal.Clerk.OnWayTrackManagement" %>

<%@ Import Namespace="NetDon.OA.Interface" %>
<%@ Import Namespace="NetDon.OA.Portal" %>
<%@ Import Namespace="NetDon.Utilities" %>
<%@ Register Src="../Controls/GridPager.ascx" TagName="GridPager" TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script language="javascript" type="text/javascript">
        var userDialogSize = { width: 900, height: window.top.$common.getClientBounds().height - 200 };


        function viewOrder(sender, args) {
            var idArray = new Array();
            var orderId = $attr(sender.get_selectedRow(), 'Id');
            idArray.push(orderId);
            $dialog('<%= ResolveUrl("~/Clerk/OnWayTrackEdit.aspx")%>?Id=' + orderId, userDialogSize, function (result) {
                if (result) {
                    $get('<%=btnReload.ClientID %>').click();
                }
            }, { Ids: idArray.toString() });
        }


        function modifyOrder(orderId) {
            var idArray = new Array();
            idArray.push(orderId);
            $dialog('<%=ResolveUrl("~/Clerk/OnWayTrackEdit.aspx") %>?Id=' + orderId, userDialogSize, function (result) {
                if (result) {
                    $get('<%=btnReload.ClientID %>').click();
                }
            }, { Ids: idArray.toString() });
        }


        function batchModifyOrder(grid) {

            var idArray = GetSelectedIds(grid);
            if (idArray.length <= 0) {
                $alert("请至少选择一笔记录。");
                return;
            }

            $dialog('<%= ResolveUrl("~/Clerk/OnWayTrackEdit.aspx") %>', userDialogSize, function (result) {
                if (result) {
                    $get('<%=btnReload.ClientID %>').click();
                }

            }, { Ids: idArray.toString() });
        }

        function GetSelectedIds(grid) {
            var idArray = new Array();
            Array.forEach($array($get(grid).getElementsByTagName("tr")), function (elt) {
                if ($attr(elt, "ID")) {
                    $(elt).find("td input:checkbox").each(function (i) {
                        if (this.checked) {
                            idArray.push($attr(elt, "ID"));
                        }
                    });
                }
            });
            return idArray;
        }


        function SelectAll(evtObj) {
            Array.forEach($array($get('<%=gridOrderList.ClientID %>').getElementsByTagName("input")), function (elt) {

                if (elt.type == "checkbox" && elt.disabled == false) {
                    elt.checked = evtObj.checked;
                }
            });
        }

  
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <asp:UpdatePanel ID="UpdatePanelFlow" runat="server">
        <ContentTemplate>
            <asp:Panel ID="Panel1" runat="server" DefaultButton="btnSearch">
                <table border="0" cellpadding="0" cellspacing="0">
                    <tr>
                        <td>
                            <NetDon:FormPanel ID="PanelCondition" runat="server" CaptionAlign="NotSet" RepeatColumns="3">
                                <Items>
                                    <NetDon:FormItem HeaderText="订单编号">
                                        <ContentTemplate>
                                            <asp:TextBox ID="txtOrderCode" runat="server"></asp:TextBox>
                                        </ContentTemplate>
                                    </NetDon:FormItem>
                                    <NetDon:FormItem HeaderText="业务类型">
                                        <ContentTemplate>
                                            <asp:DropDownList ID="ddlBusinessType" runat="server" DataSourceID="EnumDataSourceBusinessType"
                                                DataTextField="Description" DataValueField="Name">
                                            </asp:DropDownList>
                                            <NetDon:EnumDataSource ID="EnumDataSourceBusinessType" runat="server" TypeName="NetDon.OA.Interface.BusinessType">
                                            </NetDon:EnumDataSource>
                                        </ContentTemplate>
                                    </NetDon:FormItem>
                                    <NetDon:FormItem HeaderText="客户">
                                        <ContentTemplate>
                                            <asp:DropDownList ID="ddlCustomer" runat="server" DataSourceID="ObjectDataSourceCustomers"
                                                DataTextField="CustomerName" DataValueField="CustomerId" AppendDataBoundItems="true"
                                                OnSelectedIndexChanged="ddlCustomer_SelectedIndexChanged" AutoPostBack="True">
                                            </asp:DropDownList>
                                            <asp:ObjectDataSource ID="ObjectDataSourceCustomers" runat="server" OldValuesParameterFormatString="original_{0}"
                                                SelectMethod="RetrieveCustomers" TypeName="NetDon.OA.Business.MiscDataSource">
                                                <SelectParameters>
                                                    <asp:Parameter Name="areaId" />
                                                </SelectParameters>
                                            </asp:ObjectDataSource>
                                        </ContentTemplate>
                                    </NetDon:FormItem>
                                    <NetDon:FormItem HeaderText="订单状态">
                                        <ContentTemplate>
                                            <asp:DropDownList ID="ddlIssuingOrderStatus" runat="server" DataSourceID="EnumDataSourceIssuingOrderStatus"
                                                DataTextField="Description" DataValueField="Name">
                                            </asp:DropDownList>
                                            <NetDon:EnumDataSource ID="EnumDataSourceIssuingOrderStatus" EmptyItemType="All"
                                                runat="server" TypeName="NetDon.OA.Interface.OrderStatus">
                                            </NetDon:EnumDataSource>
                                        </ContentTemplate>
                                    </NetDon:FormItem>
                                    <NetDon:FormItem HeaderText="承运货物">
                                        <ContentTemplate>
                                            <asp:DropDownList ID="ddlGoodsShippedTypeId" AppendDataBoundItems="True" runat="server"
                                                DataTextField="Name" DataValueField="OID">
                                            </asp:DropDownList>
                                        </ContentTemplate>
                                    </NetDon:FormItem>
                                    <NetDon:FormItem HeaderText="运输计划号">
                                        <ContentTemplate>
                                            <asp:TextBox ID="txtTransportationPlanCode" runat="server"></asp:TextBox>
                                        </ContentTemplate>
                                    </NetDon:FormItem>
                                    <NetDon:FormItem HeaderText="线路分类">
                                        <ContentTemplate>
                                            <asp:DropDownList ID="ddlRouteTypeId" DataSourceID="ddsRouteTypeId" AppendDataBoundItems="True"
                                                runat="server" DataTextField="Name" DataValueField="Value">
                                            </asp:DropDownList>
                                            <NetDon:DictionaryDataSource ID="ddsRouteTypeId" runat="server" CategoryName="线路分类"
                                                EmptyItemType="Select">
                                            </NetDon:DictionaryDataSource>
                                        </ContentTemplate>
                                    </NetDon:FormItem>
                                    <NetDon:FormItem HeaderText="送货省份" Key="Province">
                                        <ContentTemplate>
                                            <asp:DropDownList ID="ddlProvince" runat="server" AppendDataBoundItems="true" DataTextField="Name"
                                                DataValueField="Code">
                                            </asp:DropDownList>
                                            <asp:CascadingDropDown ID="ddlProvince_CascadingDropDown" runat="server" TargetControlID="ddlProvince"
                                                ServicePath="~/CascadingService.asmx" ServiceMethod="GetProvinceContents" Category="Province"
                                                PromptText="请选择省份" LoadingText="省份加载中...">
                                            </asp:CascadingDropDown>
                                        </ContentTemplate>
                                    </NetDon:FormItem>
                                    <NetDon:FormItem HeaderText="送货城市" Key="City">
                                        <ContentTemplate>
                                            <asp:DropDownList ID="ddlCity" runat="server" AppendDataBoundItems="true" DataTextField="Name"
                                                DataValueField="Code">
                                            </asp:DropDownList>
                                            <asp:CascadingDropDown ID="ddlCity_CascadingDropDown" runat="server" ParentControlID="ddlProvince"
                                                ServicePath="~/CascadingService.asmx" ServiceMethod="GetCityContents" Category="City"
                                                TargetControlID="ddlCity" PromptText="请选择城市" LoadingText="城市加载中...">
                                            </asp:CascadingDropDown>
                                        </ContentTemplate>
                                    </NetDon:FormItem>
                                    <NetDon:FormItem HeaderText="出单日期">
                                        <ContentTemplate>
                                            <asp:TextBox ID="txtReceivingOrderDateStart" runat="server" Width="75px"></asp:TextBox>
                                            <asp:CalendarExtender ID="txtReceivingOrderDateStart_CalendarExtender" runat="server"
                                                Enabled="True" TargetControlID="txtReceivingOrderDateStart" Format="yyyy-MM-dd">
                                            </asp:CalendarExtender>
                                            <asp:Label ID="Label2" runat="server" Text="~" Style="margin-left: 5px; margin-right: 6px"></asp:Label>
                                            <asp:TextBox ID="txtReceivingOrderDateEnd" runat="server" Width="75px"></asp:TextBox>
                                            <asp:CalendarExtender ID="txtReceivingOrderDateEnd_CalendarExtender" runat="server"
                                                Enabled="True" TargetControlID="txtReceivingOrderDateEnd" Format="yyyy-MM-dd">
                                            </asp:CalendarExtender>
                                        </ContentTemplate>
                                    </NetDon:FormItem>
                                                       <NetDon:FormItem HeaderText="交货单号">
                                        <ContentTemplate>
                                            <asp:TextBox ID="txtOrderDeliveryCode" runat="server"></asp:TextBox>
                                        </ContentTemplate>
                                    </NetDon:FormItem>
                                           <NetDon:FormItem HeaderText="结算方式">
                                        <ContentTemplate>
                                            <asp:DropDownList ID="ddlCheckoutType" runat="server" DataSourceID="EnumDataSourceCheckoutType"
                                                DataTextField="Description" DataValueField="Name">
                                            </asp:DropDownList>
                                            <NetDon:EnumDataSource ID="EnumDataSourceCheckoutType" EmptyItemType="All" runat="server"
                                                TypeName="NetDon.OA.Interface.CheckoutType">
                                            </NetDon:EnumDataSource>
                                        </ContentTemplate>
                                    </NetDon:FormItem>
                                    <NetDon:FormItem HeaderText="应到货日期">
                                        <ContentTemplate>
                                            <asp:TextBox ID="txtGoodsDeliveredDateStart" runat="server" Width="75px"></asp:TextBox>
                                            <asp:CalendarExtender ID="txtPlannedShippingDateStart_CalendarExtender" runat="server"
                                                Enabled="True" TargetControlID="txtGoodsDeliveredDateStart" Format="yyyy-MM-dd">
                                            </asp:CalendarExtender>
                                            <asp:Label ID="Label1" runat="server" Text="~" Style="margin-left: 5px; margin-right: 6px"></asp:Label>
                                            <asp:TextBox ID="txtGoodsDeliveredDateEnd" runat="server" Width="75px"></asp:TextBox>
                                            <asp:CalendarExtender ID="txtPlannedShippingDateEnd_CalendarExtender" runat="server"
                                                Enabled="True" TargetControlID="txtGoodsDeliveredDateEnd" Format="yyyy-MM-dd">
                                            </asp:CalendarExtender>
                                        </ContentTemplate>
                                    </NetDon:FormItem>
                                    <NetDon:FormItem HeaderText="实际到达时间">
                                        <ContentTemplate>
                                            <asp:TextBox ID="txtActualDeliveredDateStart" runat="server" Width="75px"></asp:TextBox>
                                            <asp:CalendarExtender ID="txtActualShippingDateStart_CalendarExtender" runat="server"
                                                Enabled="True" TargetControlID="txtActualDeliveredDateStart" Format="yyyy-MM-dd">
                                            </asp:CalendarExtender>
                                            <asp:Label ID="Label3" runat="server" Text="~" Style="margin-left: 5px; margin-right: 6px"></asp:Label>
                                            <asp:TextBox ID="txtActualDeliveredDateEnd" runat="server" Width="75px"></asp:TextBox>
                                            <asp:CalendarExtender ID="txtActualShippingDateEnd_CalendarExtender" runat="server"
                                                Enabled="True" TargetControlID="txtActualDeliveredDateEnd" Format="yyyy-MM-dd">
                                            </asp:CalendarExtender>
                                        </ContentTemplate>
                                    </NetDon:FormItem>
                                    <NetDon:FormItem HeaderText="货物是否延迟">
                                        <ContentTemplate>
                                            <asp:RadioButton ID="ckbIsGoodsDelayedAll" Checked="True" runat="server" Text="全部"
                                                GroupName="IsGoodsDelayed"></asp:RadioButton>
                                            <asp:RadioButton ID="ckbIsGoodsDelayedYes" runat="server" Text="是" GroupName="IsGoodsDelayed">
                                            </asp:RadioButton>
                                            <asp:RadioButton ID="ckbIsGoodsDelayedNo" runat="server" Text="否" GroupName="IsGoodsDelayed">
                                            </asp:RadioButton>
                                        </ContentTemplate>
                                    </NetDon:FormItem>
                                    <NetDon:FormItem HeaderText="货物是否异常">
                                        <ContentTemplate>
                                            <asp:RadioButton ID="ckbIsGoodsExceptionalAll" Checked="True" runat="server" Text="全部"
                                                GroupName="IsGoodsExceptional"></asp:RadioButton>
                                            <asp:RadioButton ID="ckbIsGoodsExceptionalYes" runat="server" Text="是" GroupName="IsGoodsExceptional">
                                            </asp:RadioButton>
                                            <asp:RadioButton ID="ckbIsGoodsExceptionalNo" runat="server" Text="否" GroupName="IsGoodsExceptional">
                                            </asp:RadioButton>
                                        </ContentTemplate>
                                    </NetDon:FormItem>
                                    <%--  <NetDon:FormItem HeaderText="付款方式">
                                        <ContentTemplate>
                                            <asp:DropDownList ID="ddlPaymentMethod" DataSourceID="ddsPaymentMethod" AppendDataBoundItems="True"
                                                runat="server" DataTextField="Name" DataValueField="Value">
                                            </asp:DropDownList>
                                            <NetDon:DictionaryDataSource ID="ddsPaymentMethod" runat="server" CategoryName="装货地点"
                                                EmptyItemType="Select">
                                            </NetDon:DictionaryDataSource>
                                        </ContentTemplate>
                                    </NetDon:FormItem>--%>
                                    <NetDon:FormItem HeaderText="承运公司">
                                        <ContentTemplate>
                                            <asp:DropDownList ID="ddlCompany" runat="server" DataSourceID="ObjectDataSourceCompany"
                                                DataTextField="CompanyName" DataValueField="CompanyId" AppendDataBoundItems="true">
                                            </asp:DropDownList>
                                            <asp:ObjectDataSource ID="ObjectDataSourceCompany" runat="server" OldValuesParameterFormatString="original_{0}"
                                                SelectMethod="RetrieveCompanies" TypeName="NetDon.OA.Business.MiscDataSource">
                                            </asp:ObjectDataSource>
                                        </ContentTemplate>
                                    </NetDon:FormItem>
                                </Items>
                            </NetDon:FormPanel>
                        </td>
                    </tr>
                    <tr>
                        <td style="text-align: right">
                            <asp:Button ID="btnSearch" SkinID="Button60" runat="server" OnClick="btnSearch_Click"
                                Text="查询"></asp:Button>
                            <asp:Button ID="btnReload" runat="server" SkinID="Hidden" OnClick="btnReload_Click" />
                            <asp:Button runat="server" ID="btnBatchEdit" SkinID="Button120" Text="批量修改在途跟踪" />
                        </td>
                    </tr>
                </table>
            </asp:Panel>
            <div style="margin-top: 10px">
                <NetDon:GridView ID="gridOrderList" runat="server" AutoGenerateColumns="False" AllowSorting="true"
                    OnClientRowDblClick="viewOrder" OnRowDataBound="gridOrderList_RowDataBound">
                    <Columns>
                        <NetDon:TemplateField>
                            <HeaderStyle HorizontalAlign="Center" />
                            <HeaderTemplate>
                                <asp:CheckBox ID="chkSelectAll" runat="server" onclick="SelectAll(this)" />
                            </HeaderTemplate>
                            <ItemStyle HorizontalAlign="Center" />
                            <ItemTemplate>
                                <asp:CheckBox ID="chkSelect" runat="server" />
                            </ItemTemplate>
                        </NetDon:TemplateField>
                        <NetDon:BoundField HeaderText="订单编号" DataField="OrderCode" SortExpression="OrderCode">
                        </NetDon:BoundField>
                        <NetDon:BoundField HeaderText="客户" DataField="CustomerName" SortExpression="CustomerName">
                        </NetDon:BoundField>
                        <NetDon:TemplateField HeaderText="订单状态" SortExpression="OrderStatus">
                            <ItemTemplate>
                                <%#EnumUtilities.GetDescription((OrderStatus)Enum.Parse(typeof(OrderStatus),Eval("OrderStatus").ToString()))%>
                            </ItemTemplate>
                        </NetDon:TemplateField>
                        <NetDon:TemplateField HeaderText="承载货物" SortExpression="GoodsShippedTypeId">
                            <ItemTemplate>
                                <%#GetDictionaryItemName(Eval("GoodsShippedTypeId"))%>
                            </ItemTemplate>
                        </NetDon:TemplateField>
                        <NetDon:TemplateField HeaderText="线路分类" SortExpression="RouteTypeId">
                            <ItemTemplate>
                                <%#GetDictionaryItemName(Eval("RouteTypeId"))%>
                            </ItemTemplate>
                        </NetDon:TemplateField>
                        <NetDon:BoundField HeaderText="出单日期" DataField="ReceivingOrderDate" DataFormatString="{0:yyyy-MM-dd}"
                            SortExpression="ReceivingOrderDate">
                        </NetDon:BoundField>
                        <NetDon:BoundField HeaderText="运输计划号" DataField="TransportationPlanCode" SortExpression="TransportationPlanCode">
                        </NetDon:BoundField>
                        <NetDon:TemplateField HeaderText="在途天数" SortExpression="GoodsTravelDays">
                            <ItemTemplate>
                                <%#GetGoodsTravelDays(Eval("GoodsTravelDays"), Eval("GoodsTravelDaysUnit"))%>
                            </ItemTemplate>
                            <ItemStyle HorizontalAlign="Right"></ItemStyle>
                        </NetDon:TemplateField>
                        <NetDon:BoundField HeaderText="应到货时间" DataField="PlannedGoodsDeliveredDate" SortExpression="PlannedGoodsDeliveredDate"
                            DataFormatString="{0:yyyy-MM-dd}">
                        </NetDon:BoundField>
                        <NetDon:TemplateField HeaderText="目前所在地" SortExpression="GoodsCurrentPlace">
                            <ItemTemplate>
                                <%#GetGoodsCurrentPlace(Eval("GoodsCurrentPlace"), Eval("LastGoodsCurrentPlaceUpdatedDate"))%>
                            </ItemTemplate>
                        </NetDon:TemplateField>
                        <NetDon:BoundField HeaderText="实际到货时间" DataField="ActualDeliveredDate" SortExpression="ActualDeliveredDate"
                            DataFormatString="{0:yyyy-MM-dd}">
                        </NetDon:BoundField>
                        <NetDon:TemplateField HeaderText="是否延迟" SortExpression="IsGoodsDelayed">
                            <ItemTemplate>
                                <%#!MiscUtilities.IsNullOrEmpty(Eval("IsGoodsDelayed")) && Convert.ToBoolean(Eval("IsGoodsDelayed")) ? "是" : "否"%>
                            </ItemTemplate>
                        </NetDon:TemplateField>
                        <NetDon:BoundField HeaderText="延迟天数" SortExpression="GoodsDelayedDays" DataField="GoodsDelayedDays"
                            ItemStyle-HorizontalAlign="Right">
                        </NetDon:BoundField>
                        <NetDon:TemplateField HeaderText="是否异常" SortExpression="IsGoodsExceptional">
                            <ItemTemplate>
                                <%#!MiscUtilities.IsNullOrEmpty(Eval("IsGoodsExceptional")) && Convert.ToBoolean(Eval("IsGoodsExceptional")) ? "是" : "否"%>
                            </ItemTemplate>
                        </NetDon:TemplateField>
                        <NetDon:BoundField HeaderText="更新时间" DataField="LastUpdatedDate" SortExpression="LastUpdatedDate"
                            DataFormatString="{0:yyyy-MM-dd}">
                        </NetDon:BoundField>
                        <NetDon:BoundField HeaderText="更新人" SortExpression="LastUpdatedBy" DataField="UserName">
                        </NetDon:BoundField>
                        <NetDon:TemplateField HeaderText="操作" ItemStyle-Width="100px">
                            <ItemTemplate>
                                <asp:ImageButton ID="btnDetails" Style="margin-left: 5px" ToolTip="Details" runat="server"
                                    SkinID="ViewDetail" ImageAlign="AbsMiddle" CausesValidation="false" />
                                <asp:ImageButton ID="btnEdit" runat="server" SkinID="Modify" ImageAlign="AbsMiddle"
                                    CausesValidation="false" />
                            </ItemTemplate>
                        </NetDon:TemplateField>
                    </Columns>
                </NetDon:GridView>
                <uc1:GridPager ID="PageQueryAdapter1" runat="server" TargetControlID="gridOrderList"
                    OnPerformGetCondition="PageQueryAdapter1_PerformGetCondition" OnPerformGetRecordCount="PageQueryAdapter1_PerformGetRecordCount"
                    OnPerformGetPageData="PageQueryAdapter1_PerformGetPageData" />
            </div>
            <asp:HiddenField ID="fieldOrderId" runat="server" />
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>
